﻿using MB.Orm.DB;
using MB.RuleBase.Common;
using Model;
using Public.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Service
{
    public class BOffShelves
    {
        public BOffShelves() { }

        /// <summary>
        /// 查询指令下架数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="total"></param>
        /// <param name="parValues"></param>
        /// <returns></returns>
        public List<OffShelves> GetOffShelvesList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<OffShelves> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<OffShelves>
                                                ("Shelves", "GetOffShelves", pageIndex, pageSize, out total, parValues);
                return list;
            }
        }


        public int DeleteOffShelves(int offShelvesID)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQuery("Shelves", "DeleteOffShelves", offShelvesID);
        }

        public int AddOffShelves(OffShelves offShelves)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<OffShelves>
                            ("Shelves", "AddOffShelves", offShelves);
        }
        public int UpdateOffShelvesByID(OffShelves offShelves)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<OffShelves>
                            ("Shelves", "EditOffShelvesByID", offShelves);
        }

        public OffShelves CheckOffShelvesPrimary(int GOODSID, string BatchNo, DateTime OFFSHELVESDATE, string OFFSHELVESID)
        {
            OFFSHELVESID = string.IsNullOrEmpty(OFFSHELVESID) ? "0" : OFFSHELVESID;
            OffShelves Info = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<OffShelves>("Shelves", "CheckOffShelvesPrimary"
                , GOODSID, BatchNo, OFFSHELVESDATE, int.Parse(OFFSHELVESID)).FirstOrDefault();
            return Info;
        }

        public List<OffShelves> CheckOffShelvesPrimary(int GOODSID, DateTime OFFSHELVESDATE, string batchNo)
        {
            List<OffShelves> Info = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<OffShelves>("Shelves", "CheckOffShelvesPrimary"
                , GOODSID, OFFSHELVESDATE, batchNo);
            return Info;
        }


        public List<OffShelves> CheckOffShelvesStatus(string ImportBatch)
        {
            List<OffShelves> Info = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<OffShelves>("Shelves", "CheckOffShelvesStatus", ImportBatch);
            return Info;
        }


        /// <summary>
        /// 删除下架指令
        /// </summary>
        /// <param name="UserCellID"></param>
        /// <returns></returns>
        public int DeleteOffShelvesByImportBatch(string ImportBatch)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQuery("Shelves", "DeleteOffShelvesByImportBatch", ImportBatch);
        }

    }
}
